package com.sas.domain;

import javax.persistence.Entity;
import javax.persistence.JoinColumn; 
import javax.persistence.OneToOne;

import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.springframework.util.Assert;

@Entity
public class Person extends PersistentEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2502569117217996902L;
	@NaturalId
	private String cuilCuit;
	private String firstName;
	private String lastName;
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime birthDate;
	
	@OneToOne
	@JoinColumn(name = "addressId")
	@OnDelete(action = OnDeleteAction.CASCADE)
	private Address address;
	
	private byte [] picture;
	
	Person () {
	}

	public String getCuilCuit() {
		return cuilCuit;
	}

	public void setCuilCuit(String cuilCuit) {
		Assert.hasText(cuilCuit);
		this.cuilCuit = cuilCuit;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		Assert.hasText(firstName);
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		Assert.hasText(lastName);
		this.lastName = lastName;
	}

	public DateTime getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(DateTime birthDate) {
		Assert.notNull(birthDate);
		Assert.state(birthDate.isBeforeNow() == true);
		this.birthDate = birthDate;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		Assert.notNull(address);
		this.address = address;
	}

	public byte[] getPicture() {
		return picture;
	}

	public void setPicture(byte[] picture) {
		this.picture = picture;
	}
	
	

}
